//
//  ConfirmFetchViewController.m
//  atXiaoGeBClient
//
//  Created by Linyu Niu on 19/04/2018.
//  Copyright © 2018 Linyu Niu. All rights reserved.
//

#import "ConfirmFetchViewController.h"

@interface ConfirmFetchViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
{
    UITableView * confirmTableView;
}
@end

@implementation ConfirmFetchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    __weak ConfirmFetchViewController * weakSelf = self;
    UIView * navView = [[CTMediator sharedInstance] navgationHeadViewInTargetView:self.view params:[NSDictionary dictionaryWithObjectsAndKeys:@"确认取件",@"title", nil] leftAction:^(UIButton * sender){
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } rightAction:nil];
    confirmTableView = [self addTableViewInView:self.view frame:CGRectMake(0, navView.frame.origin.y + navView.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - navView.frame.origin.y - navView.frame.size.height) delegateAndDataSource:self];
    confirmTableView.backgroundColor = UIColorFromRGB(0xF8F8F8);
}

-(void)confirm{
    UIViewController * controller = [[CTMediator sharedInstance] waitForPayController];
    [self.navigationController pushViewController:controller animated:YES];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 15)];
    return v;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ElementTableViewCell * cell = (ElementTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    
    
    return cell.cellHeight;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ElementTableViewCell * cell = [[ElementTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    if ([indexPath section] == 0) {
        //order_confirm_pay_receiver
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UIImageView * sendIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"order_confirm_pay_send"]];
        sendIcon.frame = CGRectMake(15, 15, sendIcon.image.size.width, sendIcon.image.size.height);
        [cell addSubview:sendIcon];
        
        UILabel * sendLabel = [[UILabel alloc] init];
        sendLabel.frame = CGRectMake(sendIcon.frame.origin.x + sendIcon.frame.size.width + 5, sendIcon.frame.origin.y, tableView.frame.size.width - sendIcon.frame.origin.x - sendIcon.frame.size.width - 20, 0);
        
        sendLabel.font = [UIFont systemFontOfSize:14];;
        sendLabel.numberOfLines = 0;
        sendLabel.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0];
        [cell addSubview:sendLabel];
        
        
        
#if kDevelopment
        sendLabel.text = @"西湖区 古翠路和平大厦古翠路和平大厦古翠路…";
        
#endif
        [sendLabel enlargeHeightToKeepFontSizeWithMinHeight:sendIcon.frame.size.height];
        
        
        UIImageView * receiveIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"order_confirm_pay_send"]];
        receiveIcon.frame = CGRectMake(sendIcon.frame.origin.x, sendLabel.frame.size.height + sendLabel.frame.origin.y + 10, sendIcon.image.size.width, sendIcon.image.size.height);
        [cell addSubview:receiveIcon];
        
        UILabel * receiveLabel = [[UILabel alloc] init];
        receiveLabel.frame = CGRectMake(sendLabel.frame.origin.x, receiveIcon.frame.origin.y, sendLabel.frame.size.width , 0);
        
        receiveLabel.font = [UIFont systemFontOfSize:14];;
        receiveLabel.numberOfLines = 0;
        receiveLabel.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0];
        [cell addSubview:receiveLabel];
        
#if kDevelopment
        
        receiveLabel.text = @"浙江省 嘉兴市 桐乡市 石门镇瑞庭佳苑4栋2单元302室内";
#endif
        
        [receiveLabel enlargeHeightToKeepFontSizeWithMinHeight:receiveIcon.frame.size.height];
        cell.cellHeight = receiveLabel.frame.size.height + receiveLabel.frame.origin.y + sendIcon.frame.origin.y;
    }else if([indexPath section] == 1){
        cell.cellHeight = 60;
        cell.textLabel.textColor = UIColorFromRGB(0x333333);
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        
        UITextField * numberField = [[UITextField alloc]initWithFrame:CGRectMake(90, 0, tableView.frame.size.width - 140, cell.cellHeight)];
        numberField.delegate = self;
        numberField.font = [UIFont systemFontOfSize:14];
        numberField.textColor = UIColorFromRGB(0xBCBCBC);
        numberField.placeholder = @"请输入快递单号";
        [cell addSubview:numberField];
        
#if kDevelopment
        
        cell.textLabel.text = @"韵达单号";
#endif
        
        NSInteger width = 30;
        UIImageView * scanImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"CouricerQuery_CodeGreen"]];
        scanImgView.frame = CGRectMake(tableView.frame.size.width - 50, (cell.cellHeight - width) / 2, width, width);
        scanImgView.layer.cornerRadius = 5.0;
        scanImgView.layer.masksToBounds = YES;
        [cell addSubview:scanImgView];
    }else if([indexPath section] == 2){
        
        UILabel * label = [[UILabel alloc] init];
        label.frame = CGRectMake(0, 20, tableView.frame.size.width, 30);
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"本单收入";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0];
        [cell addSubview:label];
        
        UIImageView * lineView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"top_dot_line"]];
        lineView.frame = CGRectMake(40, label.frame.origin.y + (label.frame.size.height - 1.0) / 2, tableView.frame.size.width - 80, 1.0);
        [cell addSubview:lineView];
        
        
        UIButton * descreaseButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [descreaseButton setImage:[UIImage imageNamed:@"decrease_icon"] forState:UIControlStateNormal];
        descreaseButton.frame = CGRectMake(50, label.frame.origin.y + label.frame.size.height + 20, descreaseButton.imageView.image.size.width, descreaseButton.imageView.image.size.height);
        [cell addSubview:descreaseButton];
        
        UIButton * addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [addButton setImage:[UIImage imageNamed:@"add_icon"] forState:UIControlStateNormal];
        addButton.frame = CGRectMake(tableView.frame.size.width - 50 - addButton.imageView.image.size.width, descreaseButton.frame.origin.y, addButton.imageView.image.size.width, addButton.imageView.image.size.height);
        [cell addSubview:addButton];
        
        
        NSString * number = @"5";
        NSString * unit = @"公斤";
        
        
        UILabel * weightLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, addButton.frame.origin.y, tableView.frame.size.width, addButton.frame.size.height)];
//        [self setRichLabelWithNumber:number unit:unit numberColor:nil textColor:nil label:weightLabel];
        
        [self setRichLabelWithNumber:number unit:unit numberColor:nil textColor:nil fontSize:14 numberSize:18 label:weightLabel];
        [cell addSubview:weightLabel];
        
        
        
        UILabel * priceLabel = [[UILabel alloc] init];
        priceLabel.frame = CGRectMake(0, weightLabel.frame.origin.y + weightLabel.frame.size.height + 20,tableView.frame.size.width, 25);
        
        priceLabel.textAlignment = NSTextAlignmentCenter;
        
        [self setRichLabelWithNumber:@"28.00" unit:@"元" numberColor:nil textColor:nil fontSize:14 numberSize:23 label:priceLabel];
        [cell addSubview:priceLabel];
        
        
        UIImageView * imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"upload_camera"]];
        imgView.frame = CGRectMake(40, priceLabel.frame.origin.y + priceLabel.frame.size.height + 15, tableView.frame.size.width - 80, 100);
        imgView.contentMode = UIViewContentModeScaleAspectFit;
        [cell addSubview:imgView];
        
        UIButton * button = [[CTMediator sharedInstance] commonOrangeButton:CGRectMake(30, imgView.frame.origin.y + imgView.frame.size.height + 20, tableView.frame.size.width - 60, 40) title:@"确认取件" delegate:self action:@selector(confirm)];
        [cell addSubview:button];
        
        cell.cellHeight = button.frame.size.height + button.frame.origin.y + 10;
    }
    return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([indexPath section] == 0) {
        
    }
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    
}


@end
